package com.dqhl.community.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.base.BaseMyAdapter;
import com.dqhl.community.model.CommunityNotice;
import com.dqhl.community.util.Config;
import com.dqhl.community.util.TimeUtils;
import com.dqhl.community.util.ViewHolder;

import org.xutils.x;

import java.util.List;

/**
 * Created by LIENLIN on 2016/8/30.
 * 社区公告adapter
 */
public class CommunityNoticeAdapter extends BaseMyAdapter {

    private Context context;
    private List<CommunityNotice> communityNoticeList;

    public CommunityNoticeAdapter(Context context, List<CommunityNotice> communityNoticeList) {
        super(context);
        this.context = context;
        this.communityNoticeList = communityNoticeList;
    }

    @Override
    public int getCount() {
        return communityNoticeList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        if (view == null) {
            view = inflater.inflate(R.layout.lv_notice_tiem, viewGroup, false);
        }
        TextView tv_notice_item_title = ViewHolder.get(view, R.id.tv_notice_item_title);
        ImageView iv_notice_item_detail = ViewHolder.get(view, R.id.iv_notice_item_detail);
        TextView tv_time = ViewHolder.get(view, R.id.tv_time);

        CommunityNotice communityNotice = communityNoticeList.get(i);

        tv_notice_item_title.setText(communityNotice.getTitle());
        String time = TimeUtils.timeStamp2Date(communityNotice.getAdd_time(), "yyyy-MM-dd HH:mm");
        tv_time.setText(time);
        String picPath = communityNotice.getPicture();
        if (!"".equals(picPath) && picPath.length() >= 0) {
            x.image().bind(iv_notice_item_detail, Config.Api.base_img_url + picPath);
        }
        return view;
    }


}
